import os
from static import PROJECT_PATH

COMMON_LOG_DIR = os.path.join(PROJECT_PATH, 'logs')
TIME_LOG_PATH = os.path.join(PROJECT_PATH, 'logs')


class LogConfig:
    config = {
        "version": 1,
        "disable_existing_loggers": True,
        "formatters": {
            "simple": {
                "format": "%(asctime)s - %(levelname)s - %(module)s.py - line:%(lineno)s - %(message)s"
            }
        },

        "handlers": {
            "console": {
                "class": "logging.StreamHandler",
                "level": "DEBUG",
                "formatter": "simple",
                "stream": "ext://sys.stdout"
            },

            "debug_file_handler": {
                "class": "logging.handlers.RotatingFileHandler",
                "level": "DEBUG",
                "formatter": "simple",
                "filename": os.path.join(COMMON_LOG_DIR, 'debug.log'),
                "maxBytes": 10485760,
                "backupCount": 20,
                "encoding": "utf8"
            },

            "info_file_handler": {
                "class": "logging.handlers.RotatingFileHandler",
                "level": "INFO",
                "formatter": "simple",
                "filename": os.path.join(COMMON_LOG_DIR, 'info.log'),
                "maxBytes": 10485760,
                "backupCount": 20,
                "encoding": "utf8"
            },

            "error_file_handler": {
                "class": "logging.handlers.RotatingFileHandler",
                "level": "ERROR",
                "formatter": "simple",
                "filename": os.path.join(COMMON_LOG_DIR, 'error.log'),
                "maxBytes": 10485760,
                "backupCount": 20,
                "encoding": "utf8"
            },

            "time_file_handler": {
                "class": "logging.handlers.TimedRotatingFileHandler",
                "level": "INFO",
                "formatter": "simple",
                "filename": os.path.join(TIME_LOG_PATH, 'info'),
                "when": "S",
                "interval": 1,
                "backupCount": 5,
                # "suffix": "%Y-%m-%d.log",
                "encoding": "utf8"
            }
        },

        "loggers": {
            "my_logger": {
                "level": "DEBUG",
                "handlers": ["console", "debug_file_handler", "info_file_handler",
                             "error_file_handler"],
                "propagate": False
            }
        },

        "root": {
            "level": "INFO",
            "handlers": ["console", "info_file_handler", "error_file_handler", "time_file_handler"]
        }
    }


